package labmanager.database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import labmanager.utils.AccessDB;
import org.apache.log4j.Logger;

public class LabManagerTypeReservation {
	
	public static AccessDB mysql = new AccessDB();
	private static Logger logger = Logger.getLogger(LabManagerUser.class);
	
	public ArrayList<String> listTypeReservation(String where) {
		logger.debug("Invocando al metodo :: listTypeReservation :: Parametros recibidos: where: " + where );
		ArrayList<String> al = new ArrayList<String>();
		try{
			al.add("98");
			al.add("No se ha podido listar los tipos de reservas.");
			String query = "SELECT id, type, description FROM types_reservations WHERE " + where + ";";
			ResultSet result = mysql.executeQuery(query);
			if (result.first()){
				al.clear();
				String typeReservation = result.getInt("id") + "@#" + result.getString("type") + "@#" + result.getString("description");
				al.add(typeReservation);
				while(result.next()){
					typeReservation = result.getInt("id") + "@#" + result.getString("type") + "@#" + result.getString("description");
					al.add(typeReservation);
				}
			}else{
				al.add("97");
				al.add("No existen tipos de reservas en base.");
			}
			result.close();
			logger.debug("Respuesta al portal:" + al.toString());
			return al;
		}catch (SQLException e) {
			logger.debug("Se produjo un error en database/LabManagerTypeReservation al listar los tipos de reservas de la base de datos. " + e );
			al.add("99");
			al.add("Se ha producido un error.");
			return al;
		}
	}

}
